<%@ Page Title="" Language="C#" MasterPageFile="~/Areas/Admin/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<mesoBoard.Data.Category>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
	<script type="text/javascript">
	    var showText = '<%= Html.ThemeImage("arrow_down.gif") %> Show Forums';
	    var hideText = '<%= Html.ThemeImage("arrow_up.gif") %> Hide Forums';

	    function hideForums() {
	        $("table.categories").find("tr:gt(0)").hide();
	        $("a.togglelink").html(showText).addClass("hidden").removeClass("visible");
	    }

	    function showForums() {
	        $("table.categories").find("tr:gt(0)").show();
	        $("a.togglelink").html(hideText).addClass("visible").removeClass("hidden");
	    }
	    
	    function toggleForums(link, catID) {
	        var thelink = $(link);
	        if (thelink.hasClass("hidden")) {
	            thelink.removeClass("hidden").addClass("visible");
	            $("#cat" + catID + " tr").show();
	            thelink.html(hideText);
	        }
	        else {
	            thelink.removeClass("visible").addClass("hidden");
	            $("#cat" + catID + " tr:gt(0)").hide();
	            thelink.html(showText);
	        }
	    }

	    $(function() {
	        hideForums();
	    });
	    
</script>

    <fieldset>
        <legend><%= Html.ThemeImage("forum.png") %> Forums</legend>
    
        <div class="left">
            <%= Html.ImageLink("Create Category", Url.Action("CreateCategory"), "~/Themes/Default/Images/category.png", "Create Category", "image_link")%>
            <%= Html.ImageLink("Create Forum", Url.Action("CreateForum"), "~/Themes/Default/Images/forum.png", "Create Forum", "image_link")%>
        </div>

        <%= Html.Spacer(5) %>

        <div class="left">
            <a href="" onclick="javascript: showForums();return false;">Show all Forums</a> |
            <a href="" onclick="javascript: hideForums();return false;">Hide all Forums</a>
        </div>

        <%= Html.Spacer(10) %>

        <% foreach(Category c in Model.OrderBy(x=>x.Order)){ %>

            <table class="form_table categories" id="cat<%= c.CategoryID %>">
                <tr>
                    <td class="category_header">
                        <div class="right edit_details">
                        <a href="" onclick="javascript: toggleForums(this, <%= c.CategoryID %>); return false;" class="togglelink">Show Forums</a>
                        </div>
                        <%= c.Name %>
                        <div class="edit_details">
                        <%= c.Description %>
                        </div> 
                    </td>
                    
                    <th style="width: 20%; border-color: #27627F">
                        <%= Html.ActionLink("Edit", "EditCategory", new { CategoryID = c.CategoryID}) %>
                        <br />
                        <%= Html.AdminConfirm("Delete", Url.Action("DeleteCategory", new { CategoryID = c.CategoryID }), Url.Action("Forums")) %>
                    </th>
                    
                    <th style="width: 10%; border-color: #27627F">
                        <% if(Model.OrderBy(x=>x.Order).First().CategoryID != c.CategoryID){ %>
                        <%= Html.ImageLink("", Url.Action("Move", new {CategoryID = c.CategoryID, Direction = -1}), "~/Themes/Default/Images/arrow_up.gif", "Move Up", "")  %>
                        <%} %>

                        <% if(Model.OrderBy(x=>x.Order).Last().CategoryID != c.CategoryID){ %>
                        <%= Html.ImageLink("", Url.Action("Move",new { CategoryID = c.CategoryID, Direction = 1 }), "~/Themes/Default/Images/arrow_down.gif", "Move Down", "")%>
                        <%} %>
                    </th>
                </tr>
                <%foreach(Forum f in c.Forums.OrderBy(x=>x.Order)){%>
                <tr>
                    <td>
                    
                        <dl>
                            <dt><b><%= f.Name %></b></dt>
                            <dd>
                                <%= f.Description %>
                                <div>
                                    <b>Posts:</b> <%= f.TotalPosts %> <b>Threads:</b> <%= f.TotalThreads %>
                                </div>
                            </dd>
                        </dl>
                        
                    </td>
                    <th>
                        <%= Html.ActionLink("Edit", "EditForum", new { ForumID = f.ForumID}) %>
                        <br />
                        <%= Html.AdminConfirm("Delete", Url.Action("DeleteForum", new { ForumID = f.ForumID }), Url.Action("Forums")) %>
                        <br />
                        <%= Html.ActionLink("Permissions", "ForumPermissions", new { ForumID = f.ForumID}) %>
                    </th>
                    <th>
                        <% if(c.Forums.OrderBy(x=>x.Order).First().ForumID != f.ForumID){ %>
                        <%= Html.ImageLink("", Url.Action("Move", new {ForumID = f.ForumID, Direction = -1, CategoryID = f.CategoryID}), "~/Themes/Default/Images/arrow_up.gif", "Move Up", "")  %>
                        <%} %>
                        <% if(c.Forums.OrderBy(x=>x.Order).Last().ForumID != f.ForumID){ %>
                        <%= Html.ImageLink("", Url.Action("Move", new { ForumID = f.ForumID, Direction = 1, CategoryID = f.CategoryID }), "~/Themes/Default/Images/arrow_down.gif", "Move Down", "")%>
                        <%} %>
                    </th>
                </tr>
                <%} %>

            </table>
            <%= Html.Spacer(10) %>
        <%} %>

        <div class="left">
            <a href="" onclick="javascript: showForums();return false;">Show all Forums</a> |
            <a href="" onclick="javascript: hideForums();return false;">Hide all Forums</a>
        </div>

        <%= Html.Spacer(5) %>

        <div class="left">
            <%= Html.ImageLink("Create Category", Url.Action("CreateCategory"), "~/Themes/Default/Images/category.png", "Create Category", "image_link")%>
            <%= Html.ImageLink("Create Forum", Url.Action("CreateForum"), "~/Themes/Default/Images/forum.png", "Create Forum", "image_link")%>
        </div>
        
    </fieldset>

</asp:Content>
